import JointConfig from "./joint-config";
import Mat3 from "../../common/mat3";
import TranslationalLimitMotor from "./translational-limit-motor";
import RotationalLimitMotor from "./rotational-limit-motor";
import SpringDamper from "./spring-damper";
import Method from "../../common/method";

export default class GenericJointConfig extends JointConfig{
    constructor() {
        super();
        this.localBasis1 = new Mat3();
        this.localBasis2 = new Mat3();
        this.translationalLimitMotors = [
            new TranslationalLimitMotor().setLimits(0,0),
            new TranslationalLimitMotor().setLimits(0,0),
            new TranslationalLimitMotor().setLimits(0,0)
        ];
        this.rotationalLimitMotors = [
            new RotationalLimitMotor().setLimits(0,0),
            new RotationalLimitMotor().setLimits(0,0),
            new RotationalLimitMotor().setLimits(0,0)
        ];
        this.translationalSpringDampers = [new SpringDamper(),new SpringDamper(),new SpringDamper()];
        this.rotationalSpringDampers = [new SpringDamper(),new SpringDamper(),new SpringDamper()];
    }
    init(rigidBody1,rigidBody2,_worldAnchor,_worldBasis1,_worldBasis2) {
        let worldAnchor=Method.convertVec3(_worldAnchor);
        let worldBasis1=Method.convertMat3(_worldBasis1),worldBasis2=Method.convertMat3(_worldBasis2);
        this._init(rigidBody1,rigidBody2,worldAnchor);
        Method.inverseTransformM3(rigidBody1._transform.elements,worldBasis1.elements,this.localBasis1.elements);
        Method.inverseTransformM3(rigidBody2._transform.elements,worldBasis2.elements,this.localBasis2.elements);
        return this;
    }
}